package cn.ffcs.unm.salary.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.salary.dao.SalaryDao;
import cn.ffcs.unm.salary.model.SalaryChange;
import cn.ffcs.unm.salary.model.SalaryData;
import cn.ffcs.unm.salary.model.SalaryLevel;
import cn.ffcs.unm.salary.model.SalaryPay;
import cn.ffcs.unm.salary.model.SalaryPayProject;
import cn.ffcs.unm.salary.model.SalaryPeriod;
import cn.ffcs.unm.salary.model.SalaryPeriodScheme;
import cn.ffcs.unm.salary.model.SalarySeclv;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("salaryDao")
public class SalaryDaoImpl extends BaseDaoImpl implements SalaryDao {

	@Override
	public PageInfo queryPageInfoBySalaryPay(SalaryPay salaryPay, int currentPage, int pageSize) {

		StringBuilder sb = new StringBuilder();
		sb.append(" select  * from vie_WA_PERIODSTATE v where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != salaryPay) {
			if (!StrUtil.isEmpty(salaryPay.getMonthId())) {
				sb.append(" AND v.monthId = ? ");
				params.add(salaryPay.getMonthId());
			}
			if (!StrUtil.isEmpty(salaryPay.getOrgName())) {
				sb.append(" AND v.name LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(salaryPay.getOrgName()) + "%");
			}
			/*if (!StrUtil.isEmpty(deptCost.getOrgName())) {
				sb.append(" AND ja2.name LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(deptCost.getOrgName()) + "%");
			}*/
			
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, SalaryPay.class);
	}

	@Override
	public PageInfo queryPageInfoBySalaryPeriodScheme(SalaryPeriodScheme salaryPeriodScheme, int currentPage,
			int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select  distinct ");
		sb.append(" ja1.MONTH_ID  monthId,ja1.UNIT_ID  单位编码,ja1.PK_PERIODSCHEME pkPeriodScheme,");
		sb.append(" ja1.CODE code,ja1.NAME name,ja1.VMEMO  vmemo,");
		sb.append(" ja2.name orgName,ja1.TS  时间戳,ja1.DR  删除标志");
		sb.append(" from LDAPM_MPW_WA_PERIODSCHEME ja1 left join LDAPM_MPW_ORG_ORGS ja2"
				+ " on ( JA1.PK_ORG=JA2.PK_ORG) where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		
		if (null != salaryPeriodScheme) {
			if (!StrUtil.isEmpty(salaryPeriodScheme.getName())) {
				sb.append(" AND ja1.name LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(salaryPeriodScheme.getName()) + "%");
			}
			if (!StrUtil.isEmpty(salaryPeriodScheme.getCode())) {
				sb.append(" AND ja1.code LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(salaryPeriodScheme.getCode()) + "%");
			}
			
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, SalaryPeriodScheme.class);
	}

	@Override
	public PageInfo queryPageInfoBySalaryPeriod(SalaryPeriod salaryPeriod, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select  distinct ");
		sb.append(" ja1.MONTH_ID monthId,ja1.UNIT_ID  单位编码,ja1.PK_WA_PERIOD  pkPeriod,ja1.PK_PERIODSCHEME  pKPeriodScheme,");
		sb.append(" ja1.CYEAR  year,ja1.CPERIOD  period,ja1.CSTARTDATE  startTime,ja1.CENDDATE  endTime,");
		sb.append(" ja1.VCALYEAR  vcalYear,ja1.VCALMONTH  vcalMonth,ja1.CACCYEAR  caccYear,ja1.CACCPERIOD caccPeriod,");
		sb.append(" ja1.TS  时间戳,ja1.  DR  删除标志");
		sb.append(" from LDAPM_MPW_WA_PERIOD ja1 where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		
		/*if (null != salaryPeriod) {
			if (!StrUtil.isEmpty(salaryPeriod.getName())) {
				sb.append(" AND ja1.name LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(salaryPeriod.getName()) + "%");
			}
			if (!StrUtil.isEmpty(salaryPeriod.getCode())) {
				sb.append(" AND ja1.code LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(salaryPeriod.getCode()) + "%");
			}
			
		}*/
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, SalaryPeriod.class);
	}

	@Override
	public PageInfo queryPageInfoBySalaryPayProject(
			SalaryPayProject salaryPayProject, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from vie_WA_CLASSITEM v where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != salaryPayProject) {
			if (!StrUtil.isEmpty(salaryPayProject.getMonthId())) {
				sb.append(" AND v.monthId = ? ");
				params.add(salaryPayProject.getMonthId());
			}
			if (!StrUtil.isEmpty(salaryPayProject.getName())) {
				sb.append(" AND v.name LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(salaryPayProject.getName()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, SalaryPayProject.class);
	}

	@Override
	public PageInfo queryPageInfoBySalaryChange(SalaryChange salaryChange, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from vie_PSNDOC_WADOC v where 1=1  ");
		List<Object> params = new ArrayList<Object>();
		if (null != salaryChange) {
			if (!StrUtil.isEmpty(salaryChange.getMonthId())) {
				sb.append(" AND v.monthId = ? ");
				params.add(salaryChange.getMonthId());
			}
			if (!StrUtil.isEmpty(salaryChange.getName())) {
				sb.append(" AND v.name LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(salaryChange.getName()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, SalaryChange.class);
	}

	@Override
	public PageInfo queryPageInfoBySalaryLevel(SalaryLevel salaryLevel, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select  ");
		sb.append(" ja1.MONTH_ID  monthID,ja1.UNIT_ID  unitId,ja1.PK_WA_PRMLV  pkWaPrmlv,ja1.DISPLAYINDEX  displayIndex, ");
		sb.append(" ja1.DR  dr,ja1.LEVELNAME levelName,ja1.PK_WA_GRD  pkWaGrd ,ja1.TS  ts ");
		sb.append("  from LDAPM_MPW_WA_PRMLV ja1 where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != salaryLevel) {
			if (!StrUtil.isEmpty(salaryLevel.getMonthId())) {
				sb.append(" AND ja1.MONTH_ID = ? ");
				params.add(salaryLevel.getMonthId());
			}
			if (!StrUtil.isEmpty(salaryLevel.getLevelName())) {
				sb.append(" AND ja1.LEVELNAME LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(salaryLevel.getLevelName()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, SalaryLevel.class);
	}

	@Override
	public PageInfo queryPageInfoBySalarySeclv(SalarySeclv salarySeclv, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from vie_WA_SECLV v where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != salarySeclv) {
			if (!StrUtil.isEmpty(salarySeclv.getMonthId())) {
				sb.append(" AND v.monthId = ? ");
				params.add(salarySeclv.getMonthId());
			}
			if (!StrUtil.isEmpty(salarySeclv.getLevelName())) {
				sb.append(" AND v.LEVELNAME LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(salarySeclv.getLevelName()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, SalarySeclv.class);
	}

	@Override
	public PageInfo queryPageInfoBySalaryData(SalaryData salaryData, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select distinct ja1.MONTH_ID  monthId,ja1.UNIT_ID  单位编码,ja1.ASSGID  人员任职ID,ja1.C_1  note, ");
		sb.append(" DECODE(ja1.CACULATEFLAG,'N','否','是') caculateFlag,DECODE(ja1.CHECKFLAG,'N','否','是')  checkFlag, ");
		sb.append(" ja1.CPAYDATE cpayDate,ja1.CPERIOD  period,ja1.CYEAR  year,ja1.CYEARPERIOD  yearPeriod,ja1.DERATEPTG  derateptg, ");
		sb.append(" ja1.DR  dr,ja1.EXPENSE_DEDUCTION  exDeduction,ja1.F_1  total,ja1.F_100  f100, ");
		sb.append(" ja1.F_101  f101,ja1.F_102  f102,ja1.F_103  f103,ja1.F_104  f104, ");
		sb.append(" ja1.F_105 f105,ja1.F_106 f106,ja1.F_107  f107,ja1.F_108 f108,ja1.F_116  f116, ");
		sb.append(" ja1.F_118  f118,ja1.F_119 f119,ja1.F_120  f120,ja1.F_121  f121, ");
		sb.append(" ja1.F_122  f122,ja1.F_123  f123,ja1.F_124  f124, ");
		sb.append(" ja1.F_125  f125,ja1.F_126 f126,ja1.F_127 f127,ja1.F_128  f128,ja1.F_129  f129, ");
		sb.append(" ja1.F_130  f130,ja1.F_131  f131,ja1.F_132 f132,ja1.F_133  f133,");
		sb.append(" ja1.F_134  f134,ja1.F_135 f135,ja1.F_136  f136,ja1.F_137  f137,");
		sb.append(" ja1.F_138  f138,ja1.F_139  f139,ja1.F_140  f140,ja1.F_141  f141,ja1.F_142  f142,");
		sb.append(" ja1.F_143  f143,ja1.F_144  f144,ja1.F_15  f15,ja1.F_155  f155,ja1.F_156  f156,");
		sb.append(" ja1.F_157  f157,ja1.F_158  f158,ja1.F_159  f159,ja1.F_16  f16,");
		sb.append(" ja1.F_160  f160,ja1.F_161  f161,ja1.F_162  f162,ja1.F_163 f163,");
		sb.append(" ja1.F_166  f166,ja1.F_167  f167,ja1.F_169  f169,ja1.F_177  f177,ja1.F_18 f18,");
		sb.append(" ja1.F_180  f180,ja1.F_181  f181,ja1.F_182  f182,ja1.F_183  f183,");
		sb.append(" ja1.F_184  f184,ja1.F_185  f185,ja1.F_186 f186,ja1.F_187  f187,ja1.F_188  f188,");
		sb.append(" ja1.F_189  f189,ja1.F_19  f19,ja1.F_190  f190,ja1.F_191  f191,ja1.F_192  f192,");
		sb.append(" ja1.F_2  f2,ja1.F_21  f21,ja1.F_22  f22,ja1.F_23  f23,ja1.F_28  f28,ja1.F_29  f29,");
		sb.append(" ja1.F_3  f3,ja1.F_30  f30,ja1.F_31  f31,ja1.F_32  f32,ja1.F_33  f33,");
		sb.append(" ja1.F_34  f34,ja1.F_35  f35,ja1.F_36  f36,ja1.F_37 f37,ja1.F_38  f38,ja1.F_39  f39,");
		sb.append(" ja1.F_4  f4,ja1.F_40  f40,ja1.F_41  f41,ja1.F_42 f42,ja1.F_43  f43,ja1.F_44  f44,");
		sb.append(" ja1.F_45  f45,ja1.F_46  f46,ja1.F_47  f47,ja1.F_49  f49,ja1.F_5  f5,ja1.F_50 f50,");
		sb.append(" ja1.F_51  f51,ja1.F_57  f57,ja1.F_58  f58,ja1.F_59  f59,ja1.F_6 f6,");
		sb.append(" ja1.F_60  f60,ja1.F_61  f61,ja1.F_62  f62,ja1.F_63  f63,");
		sb.append(" ja1.F_64  f64,ja1.F_65  f65,ja1.F_66  f66,ja1.F_67  f67,");
		sb.append(" ja1.F_7  f7,ja1.F_71  f71,ja1.F_72 f72,ja1.F_73  f73,ja1.F_74  f74,");
		sb.append(" ja1.F_75  f75,ja1.F_76  f76,ja1.F_77  f77,ja1.F_78  f78,ja1.F_8  f8,");
		sb.append(" ja1.F_81 f81,ja1.F_82  f82,ja1.F_83  f83,ja1.F_84  f84,ja1.F_85  f85,");
		sb.append(" ja1.F_86 f86,ja1.F_87  f87,ja1.F_88  f88,ja1.F_89  f89,ja1.F_9 f9,");
		sb.append(" ja1.F_90  f90,ja1.F_91  f91,ja1.F_92 f92,ja1.F_93  f93,ja1.F_94  f94,");
		sb.append(" ja1.F_95 f95,ja1.F_96  f96,ja1.F_97 f97,ja1.F_98  f98,ja1.F_99  f99,");
		sb.append(" DECODE(ja1.FIPENDFLAG,'N','否','是')  fipendFlag,DECODE(ja1.ISDERATE,'N','否','是')  isDerate,");
		sb.append(" DECODE(ja1.ISNDEBUCT,'N','否','是')  isNdebuct,DECODE(ja1.ISRULEHINT,'N','否','是')  isRulehint,");
		sb.append(" ja1.NQUICKDEBUCT  nquickdebuct,DECODE(ja1.PARTFLAG,'N','否','是') partFlag,ja1.PK_PSNORG  pkPsnOrg,ja1.PK_LIABILITYORG  pkLiab,");
		sb.append(" ja2.name  orgName,ja3.name  name,ja1.PK_WA_DATA paWaData,DECODE(ja1.STOPFLAG,'N','否','是')  stopFlag,ja1.TAXABLE_INCOME  taxableIncome,");
		sb.append(" ja1.TAXRATE  taxRate,ja1.TAXTABLEID  taxTableId,ja1.TAXTYPE taxType,ja1.TS  时间戳,ja1.VPAYCOMMENT  vpayComment,");
		sb.append(" ja1.F_210   f210,ja1.F_211  f211,ja1.F_212   f212,ja1.F_213  f213,");
		sb.append(" ja1.F_214   f214,ja1.F_215 f215,ja1.F_216   f216,ja1.F_217 f217,ja1.F_218  f218,");
		sb.append(" ja1.F_219   f219,ja1.F_224   f224,ja1.F_225   f225 ,ja1.F_226  f226,");
		sb.append(" ja1.F_227  f227,ja1.F_228   f228,ja1.F_229   f229,ja1.F_230  f230,ja1.F_231   f231,ja1.F_232   f232,");
		sb.append(" ja1.PK_BANKDOC1   pkBankDoc1,ja1.F_109  f109,ja1.F_145  f145,ja1.F_164  f164,");
		sb.append(" ja1.F_168  f168,ja1.F_170  f170,ja1.F_171  f171,ja1.F_173  f173,ja1.F_178  f178,");
		sb.append(" ja1.F_193  f193,ja1.F_194  f194,ja1.F_195  住房公积金预留2,ja1.F_20  月度绩效工资预留1,");
		sb.append(" ja1.F_24  年度绩效工资预留1,ja1.PK_BANKACCBAS1 pkBankAccbas1");
		sb.append("  from LDAPM_MPW_WA_DATA ja1, LDAPM_MPW_ORG_ORGS ja2 ,LDAPM_MPW_bd_psndoc ja3");
		sb.append("  where JA1.PK_ORG=JA2.PK_ORG and JA1.pk_psndoc=JA3.pk_psndoc "
				+ " and JA1.MONTH_ID=JA2.MONTH_ID and JA1.MONTH_ID=JA3.MONTH_ID");
		
		
		List<Object> params = new ArrayList<Object>();
		if (null != salaryData) {
			if (!StrUtil.isEmpty(salaryData.getMonthId())) {
				sb.append(" AND ja1.MONTH_ID = ? ");
				params.add(salaryData.getMonthId());
			}
			if (!StrUtil.isEmpty(salaryData.getName())) {
				sb.append(" AND ja3.name LIKE ? ");
				params.add("%" + StringEscapeUtils.escapeSql(salaryData.getName()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, SalaryData.class);
	}

}
